package visualInterface;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;

public class S extends JFrame {
	private JLabel edition = new JLabel("Editie:");
	private JLabel season = new JLabel("Nume sezon: ");
	private JLabel rounds = new JLabel("Numar etape: ");
	private JLabel teams = new JLabel("Numar echipe: ");
	private JLabel teamsName = new JLabel("Nume echipa: ");

	private JTextField seasonEdition = new JTextField();
	private JTextField seasonName = new JTextField();
	private JTextField roundsNumber = new JTextField();
	private JTextField teamsNumber = new JTextField();

	private JComboBox teamName = new JComboBox();

	private JButton saveSeason = new JButton("Salveaza sezon");
	private JButton saveTeam = new JButton("Salveaza");
	private JButton cancelTeam = new JButton("Anuleaza");
	private JButton deleteTeam = new JButton("Sterge");

	BackgroungImages mainPanel;

	public S() {
		setFrame();
	}

	public void addComponent() {
		mainPanel = new BackgroungImages("details.jpg", this);
		GridBagLayout mainPanelLayout = new GridBagLayout();
		GridBagConstraints constraints = new GridBagConstraints();
		mainPanel.setLayout(mainPanelLayout);

		 constraints.insets=new Insets(3,3,3,3);
		constraints.anchor=GridBagConstraints.WEST;
	
		constraints.gridx=0;
		constraints.gridy=0;
		mainPanel.add(edition,constraints);
		
		constraints.gridx=2;
		constraints.gridy=0;
		mainPanel.add(seasonEdition,constraints);
		
		
		constraints.gridx=0;
		constraints.gridy=1;
		mainPanel.add(season,constraints);
		
		constraints.gridx=2;
		constraints.gridy=1;
		mainPanel.add(seasonName,constraints);
		
		
		constraints.gridx=0;
		constraints.gridy=2;
		mainPanel.add(teams,constraints);
		
		constraints.gridx=2;
		constraints.gridy=2;
		mainPanel.add(teamsNumber,constraints);

	
		constraints.gridx=0;
		constraints.gridy=3;
		mainPanel.add(rounds,constraints);
		
		constraints.gridx=2;
		constraints.gridy=3;
		mainPanel.add(roundsNumber,constraints);

	//	constraints.anchor=GridBagConstraints.CENTER;
		constraints.gridx=1;
		constraints.gridy=4;
		mainPanel.add(saveSeason,constraints);
	
		constraints.gridx=0;
		constraints.gridy=5;
		mainPanel.add(teamsName,constraints);
		
		constraints.gridx=2;
		constraints.gridy=5;
		mainPanel.add(teamName,constraints);

		constraints.anchor=GridBagConstraints.CENTER;
		
		constraints.gridx=0;
		constraints.gridy=6;
		mainPanel.add(saveTeam,constraints);
		
		constraints.gridx=1;
		constraints.gridy=6;
		mainPanel.add(cancelTeam,constraints);
		
		constraints.gridx=2;
		constraints.gridy=6;
		mainPanel.add(deleteTeam,constraints);

		

		getContentPane().add(mainPanel);
	}

	public void hideFrame() {
		setVisible(false);
	}

	private void setComponent() {
		seasonEdition.setPreferredSize(new Dimension(140,20));
		seasonEdition.setBorder(BorderFactory.createEtchedBorder(0));
		seasonEdition.setBackground(Color.WHITE);
		
		seasonName.setPreferredSize(new Dimension(140, 20));
		seasonName.setBorder(BorderFactory.createEtchedBorder(0));
		seasonName.setBackground(Color.WHITE);

		roundsNumber.setPreferredSize(new Dimension(50, 20));
		roundsNumber.setBorder(BorderFactory.createEtchedBorder(0));
		roundsNumber.setBackground(Color.WHITE);

		teamsNumber.setPreferredSize(new Dimension(50, 20));
		teamsNumber.setBorder(BorderFactory.createEtchedBorder(0));
		teamsNumber.setBackground(Color.WHITE);

		teamName.setPreferredSize(new Dimension(140, 20));
		teamName.setBorder(BorderFactory.createEtchedBorder(0));
		teamName.setBackground(Color.WHITE);
		teamName.setEnabled(false);
		saveTeam.setEnabled(false);
		deleteTeam.setEnabled(false);
		cancelTeam.setEnabled(false);
	}

	private void setFrame() {
		setComponent();
		addComponent();
		setFramePosition();
	}

	public void setFramePosition() {
		Dimension screenDimension = Toolkit.getDefaultToolkit().getScreenSize();
		Dimension frameDimension = new Dimension(850, 850);
		setSize(frameDimension);
		Point leftCorner = new Point();
		leftCorner.x = (screenDimension.width - frameDimension.width) / 2;
		leftCorner.y = (screenDimension.height - frameDimension.height) / 2;
		setLocation(leftCorner);
		setMinimumSize(frameDimension);
	}

	public void showFrame() {
		setVisible(true);
	}
}
